package com.home.job.zh2.job2;


import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

public class Order {
    public String id;
    public String goodsId;
    public String goodsName;
    public int goodsNumber;
    public double goodsPrice;
    public Date orderSubmitTime;
    public Date paymentTime;

    public double getGoodsPrice() {
        return goodsPrice;
    }

    public Order() {
    }

    public Order(Item item, int goodsNumber) {
        this.id = UUID.randomUUID().toString();
        this.goodsId = item.id;
        this.goodsName = item.name;
        this.goodsNumber = goodsNumber;
        this.goodsPrice = item.getTotalPrice(goodsNumber);
        this.orderSubmitTime = new Date();
    }

    @Override
    public String toString() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String ss = "订单{" +
                " 物品名称 = " + goodsName +
                ", 物品数量 = " + goodsNumber +
                ", 订单价格 = " + goodsPrice +
                ", 订单提交时间 = " + sdf.format(orderSubmitTime);
        if (null == paymentTime) {
            ss += ", 支付状态 = 未支付 }";
        } else {
            ss += ", 支付时间 = " + sdf.format(paymentTime) + " }";
        }
        return ss;
    }
}
